﻿using System.Reflection;
using System.Security.Permissions;
using System.Globalization;
using System.Collections.Specialized;
namespace System.Web
{
    public class NetHttpModuleCollection : NameObjectCollectionBase
    {
        internal static StringComparer CaseInsensitiveInvariantKeyComparer = StringComparer.Create(CultureInfo.InvariantCulture, true);
        private INetHttpModule[] _all;
        private string[] _allKeys;

        internal NetHttpModuleCollection()
            : base(CaseInsensitiveInvariantKeyComparer) { }

        public void AddModule(string name, INetHttpModule m)
        {
            _all = null;
            _allKeys = null;
            base.BaseAdd(name, m);
        }

        public void CopyTo(Array dest, int index)
        {
            if (_all == null)
            {
                int count = Count;
                _all = new INetHttpModule[count];
                for (int index2 = 0; index2 < count; index2++)
                    _all[index2] = Get(index2);
            }
            if (_all != null)
                _all.CopyTo(dest, index);
        }

        public INetHttpModule Get(int index) { return (INetHttpModule)BaseGet(index); }
        public INetHttpModule Get(string name) { return (INetHttpModule)BaseGet(name); }
        public string GetKey(int index) { return BaseGetKey(index); }
        public string[] AllKeys
        {
            get
            {
                if (_allKeys == null)
                    _allKeys = base.BaseGetAllKeys();
                return _allKeys;
            }
        }

        public INetHttpModule this[string name]
        {
            get { return Get(name); }
        }

        public INetHttpModule this[int index]
        {
            get { return Get(index); }
        }
    }
}
